package model

import (
	"github.com/jinzhu/gorm"
)

type User struct {
	*Model
	NickName  string `json:"nick_name"`
	WChatId   string `json:"w_chat_id"`
	AvatarUrl string `json:"avatar_url"`
}

func (u User) TableName() string {
	return "user"
}

func (u User) Get(db *gorm.DB) (User, error) {
	var user User
	err := db.Where("nick_name = ? AND w_chat_id = ? AND avatar_url = ?"+
		" AND is_del = ?", u.NickName, u.WChatId, u.AvatarUrl, 0).First(&user).Error

	return user, err
}

func (u User) Create(db *gorm.DB) error {
	err := db.Create(&u).Error
	return err
}
